package cc.mrbird.plan.controller;

import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.plan.domain.Rehearse;
import cc.mrbird.plan.domain.Training;
import cc.mrbird.plan.service.RehearseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(description = "培训信息管理接口")
@Controller
public class RehearseController extends BaseController{
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RehearseService rehearseService;

    @ApiOperation(value = "培训信息添加")
    @RequestMapping(value = "rehearse/add",method = RequestMethod.POST)
    @ResponseBody
    public ResponseBo add(Rehearse rehearse) {
        try {
            Rehearse result = this.rehearseService.findById(rehearse.getUnit_id());
            if (result != null) {
                return ResponseBo.warn("该培训信息已存在！");
            }
            this.rehearseService.add(rehearse);
            return ResponseBo.ok();
        } catch (Exception e) {
            log.error("添加失败", e);
            return ResponseBo.error("添加失败，请重新添加！");
        }
    }
    @ApiOperation(value = "根据id查询培训信息")
    @Log("根据id查询培训信息")
    /*@RequiresPermissions("rehearse:findById")*/
    @RequestMapping(value = "rehearse/findById",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo findById(Integer id) {
        try {
            Rehearse rehearse = this.rehearseService.findById(id);
            return ResponseBo.ok(rehearse);
        } catch (Exception e) {
            log.error("根据id查询培训信息失败", e);
            return ResponseBo.error("根据id查询培训信息失败，请联系网站管理员！");
        }
    }
    @ApiOperation(value = "修改培训信息信息")
    @Log("修改培训信息信息")
    /* @RequiresPermissions("rehearse:update")*/
    @RequestMapping(value = "rehearse/update" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseBo update(Rehearse rehearse) {
        try {
            this.rehearseService.update(rehearse);
            return ResponseBo.ok("修改培训信息信息成功！");
        } catch (Exception e) {
            log.error("修改培训信息信息失败", e);
            return ResponseBo.error("修改培训信息失败，请联系网站管理员！");
        }
    }
    @Log("删除培训信息")
    /*@RequiresPermissions("rehearse:delete")*/
    @RequestMapping(value = "rehearse/delete",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo delete(String ids) {
        try {
            this.rehearseService.delete(ids);
            return ResponseBo.ok("删除培训信息成功！");
        } catch (Exception e) {
            log.error("删除培训信息失败", e);
            return ResponseBo.error("删除培训信息失败，请联系网站管理员！");
        }
    }
}
